

Vue.http.interceptors.push(function(request) {

  // modify request
  // request.method = 'POST';

  // return response callback
  return function(response) {
		
		console.log(response)
		if(response.status==403||response.status==0){
			var name=window.localStorage.getItem("name");
			var pwd=window.localStorage.getItem("pwd");
	
			 if((name!=null&&pwd!=null)&&(name!=""&&pwd!="")){
								 Vue.http.headers.common.Authorization=null
								 layer.msg("正在登录");
								 this.$http.post(global_url+'/login', {name: name,pwd:pwd})
									 .then(response => {
										
										var tk='Bearer '+response.body.token;
						
										window.localStorage.setItem('token',tk);
										request.headers.set('Authorization',tk);
										Vue.http.headers.common.Authorization = tk;
										this.$http.post(global_url+'/admin/isadmin')
											.then(
											response=>{
                             layer.msg("登录成功，请刷新页面");
                      
											},					
											response=>{
							
												if(response.status==0){
													layer.msg("未响应！请稍后再试吧！");
												}
												else if (!response.ok){
													top.window.location.href='/backstage_management/page/login/login.html';
													
												}
											})
							
									  }, response => {
					
										if(response.status==0){
											layer.msg("未响应！请稍后再试吧！");
										} else{
											
											layer.msg(response.body.msg);
										}
							
								});
			
			
			
				}else{
					top.window.location.href='/backstage_management/page/login/login.html';
					
				}

		}
		else if(response.status>=400){
			
				layer.msg("请求服务失败，错误代码："+response.status);
		}
		
  };
});



Vue.http.interceptor.before = function(request) {

  // override before interceptor
	request.headers.set('Authorization',window.localStorage.getItem("token"));

};